package _1109_Corporate_Flight_Bookings;

import java.util.Arrays;

/**
 * Date: 2021/8/31 9:28
 */
public class Solution {

    public int[] corpFlightBookings(int[][] bookings, int n) {
        int[] t = new int[n + 10];
        for (int[] item : bookings) {
            int a = item[0], b = item[1], w = item[2];
            t[a] += w;
            t[b + 1] -= w;
        }
        int[] res = new int[n];
        for (int i = 1; i <= n; i++) {
            t[i] += t[i - 1];
            res[i - 1] = t[i];
        }
        return res;
    }

    public static void main(String[] args) {

        int[][] bookings = {
                {1, 2, 10},
                {2, 3, 20},
                {2, 5, 25}
        };
        System.out.println(Arrays.toString((new Solution()).corpFlightBookings(bookings, 5)));
    }
}
